package play.modules.m4fcity;

import com.google.gson.JsonObject;

import play.Play;
import play.libs.WS;
import play.libs.WS.WSRequest;
import play.libs.ws.WSUrlFetch;
import play.modules.m4fcity.M4FCityProfile;

public class M4FCityApiService {
	private static M4FCityApiService service;
	private M4FCityProfile profile;
	
	public M4FCityApiService(M4FCityProfile profile) {
		this.profile = profile;
	}
	
	
	public OrganizationCity gerOrganization() {
		String uri = String.format("%s?oauth_token=%s", Play.configuration.getProperty("m4fcity.organizationInfoUrl"), this.profile.getAccessToken());
		WSUrlFetch ws = new WSUrlFetch();
		WSRequest req = ws.newRequest(uri, "UTF-8");
		
		JsonObject jsonData = req.get().getJson().getAsJsonObject();
		
		return new OrganizationCity(jsonData);
	}
	
}
